﻿using Hangfire;
using Hangfire.Logging;
using Hangfire.Logging.LogProviders;
using Hangfire.Redis;
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Topshelf;
using Topshelf.Logging;

namespace AVIS.TaskScheduler.ServerNode
{
    class Program
    {
        static void Main(string[] args)
        {
            string serviceName = ConfigurationManager.AppSettings["WindowsService.ServiceName"];
            string displayName = ConfigurationManager.AppSettings["WindowsService.DisplayName"];
            string description = ConfigurationManager.AppSettings["WindowsService.Description"];

            HostFactory.Run(x =>
            {
                x.UseLog4Net("log4net.config");
                x.Service<HangfireService>();
                x.RunAsLocalSystem();
                x.SetStartTimeout(TimeSpan.FromSeconds(10));
                x.SetStopTimeout(TimeSpan.FromSeconds(10));

                x.SetDescription(description);
                x.SetDisplayName(displayName);
                x.SetServiceName(serviceName);

                x.OnException((exception) =>
                {
                    HostLogger.Get<HangfireService>().Error($"Window服务（{displayName}）出错:{exception.Message}", exception);
                });
            });
        }
    }
}
